package com.easy.thread.handler;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Packge com.easy.thread.handler
 * @Autor linNaibin
 * @Description
 * @Version 1.0
 * @Date 2021/1/12 16:40
 */
public class EasyRejectedExecutionHandler implements RejectedExecutionHandler {

    /**
     * 交给队列处理，这里使用的是LinkedBlockingQueue，因此是个阻塞的策略
     */
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        if (!executor.isShutdown()) {
            try {
                executor.getQueue().put(r);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
